﻿Ext.ns("PcaGlobal");

PcaGlobal = {
    showError: function (errorMensaje) {
        Ext.Msg.show({ title: 'Error', msg: errorMensaje, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR });
    },

    fnValidarForm: function () {
        var form = this.up('window').down('form');
        return form.getForm().isValid();
    },

    fnSetMaxLength: function (length, control) {

        if (length != 0) {
            control.maxLength = length;
            control.enforceMaxLength = true;
            control.inputEl.set({
                maxLength: length
            });
        }
        else {
            control.maxLength = 20;
            control.enforceMaxLength = false;
            control.inputEl.set({
                maxLength: 20
            });
        }
        control.minLength = length;
        control.validate();
    },

    hashCode: function (str) {
        var hash = 1315423911;
        for (var i = 0; i < str.length; i++) {
            hash ^= ((hash << 5) + str.charCodeAt(i) + (hash >> 2));
        }
        return (hash & 0x7FFFFFFF);
    },

    //Para desabilitar cache, mas info en https://support.google.com/dfa/partner/answer/134572
    fnGetRandomId: function () {
        var axel = Math.random() + "";
        var num = axel * 1000000000000000000;
        return '?ord=' + num;
    },

    //Devuelve la Ubicacion de la aplicacion
    fnGetPath: function () {
        return 'http://localhost:4701/';
    },

    numberFormat: function (value, metaData, record) {
        return Ext.util.Format.number(value, '000,000.00');
    },

    moneyFormat: function (value, metaData, record) {
        return record.data.siglas_moneda + ' ' + Ext.util.Format.number(value, '000,000.00');
    },

    //fnTestPrinter:function(proxyUrl){
    //    Ext.Ajax.request({
    //        url: proxyUrl,
    //        method: 'GET',
    //        success: function (response) {
    //            console.log("ok");
    //            return true;
    //        },
    //        failure: function (response) {
    //            console.log("false");
    //            return false;
    //        },
    //        scope: this
    //    });
    //},

    fnImprimirTicket: function (ticket) {
        Ext.Ajax.request({
            url: ticket.proxyUrl,
            method: 'POST',
            params: {
                puerto: ticket.puerto,  
                data: ticket.data
            },
            success: function (response) { },
            failure: function (response) {
                console.log(response);
            },
            scope: this
        });
    }
};